import time
import random

# -----------------------------------------------------------------------------
# Globals 
# -----------------------------------------------------------------------------
random.seed((long)(time.time() * 1000000)) # seed the random num generator
ALPHA  = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
ALPHA_NUM = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
LC_ALPHA = "abcdefghijklmnopqrstuvwxyz"
UC_ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
LC_ALPHA_NUM = "abcdefghijklmnopqrstuvwxyz1234567890"
LC_ALPHA_NUM = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
CAPTCHA = "QWERTYUPASDFGHJKLZXCVBNM"
FIFTY_TWO = len(ALPHA) - 1
SIXTY_TWO = len(ALPHA_NUM) - 1
TWENTY_SIX = len(LC_ALPHA) - 1
THIRTY_SIX = len(LC_ALPHA_NUM) - 1
TWENTY_FOUR = len(CAPTCHA) - 1


# -----------------------------------------------------------------------------
# Random key generators
# -----------------------------------------------------------------------------
def get_key(size=24):
	""" Regular old random string generator.
	"""
	global ALPHA, FIFTY_TWO
	return "".join([ALPHA[random.randint(0, FIFTY_TWO)] for i in xrange(size)])

# -----------------------------------------------------------------------------
def get_rand_digits(size=1):
	return "".join([`random.randint(0,9)` for x in xrange(size)])

# -----------------------------------------------------------------------------
def get_alpha(size=24):
	return get_key(size)

# -----------------------------------------------------------------------------
def get_alpha_num(size=24):
	""" gen mix case alpha num string 
	"""
	global ALPHA_NUM, SIXTY_TWO 
	return "".join([
		ALPHA_NUM[random.randint(0, SIXTY_TWO)] for i in xrange(size)])

# -----------------------------------------------------------------------------
def get_lc_alpha(size=24):
	""" gen lower case alpha string 
	"""
	global LC_ALPHA, TWENTY_SIX 
	return "".join([
		LC_ALPHA[random.randint(0, TWENTY_SIX)] for i in xrange(size)])

# -----------------------------------------------------------------------------
def get_uc_alpha(size=24):
	""" gen upper case alpha string 
	"""
	global UC_ALPHA, TWENTY_SIX 
	return "".join([
		UC_ALPHA[random.randint(0, TWENTY_SIX)] for i in xrange(size)])

# -----------------------------------------------------------------------------
def get_lc_alpha_num(size=24):
	""" gen lower case alpha num string 
	"""
	global LC_ALPHA_NUM, THIRTY_SIX 
	return "".join([
		LC_ALPHA_NUM[random.randint(0, THIRTY_SIX)] for i in xrange(size)])

# -----------------------------------------------------------------------------
def get_uc_alpha_num(size=24):
	""" gen upper case alpha num string 
	"""
	global UC_ALPHA_NUM, THIRTY_SIX 
	return "".join([
		UC_ALPHA_NUM[random.randint(0, THIRTY_SIX)] for i in xrange(size)])

# -----------------------------------------------------------------------------
def get_captcha_word(size=5):
	""" get rand captcha text using captcha cool chars
	"""
	global CAPTCHA, TWENTY_FOUR
	return "".join([
		CAPTCHA[random.randint(0, TWENTY_FOUR)] for i in xrange(size)])
